create or replace function insertPosterminalModel(
	out xml, inout xml
	)
as
$$
	declare
		-- alias is name for stored procedure parameters
		executeStatusData 			alias for $1;
		posterminalModelData		alias for $2;
		
		-- variable for node data
		vIdModel 		bigint 	:= null;
		vNameModel		text 	:= null;
		vIdProducer		integer := null;
		
		-- node path
		vIdNode			varchar(100) := '/posterminalmodel/@id';
		vNameNode		varchar(100) := '/posterminalmodel/posterminalmodelname';
		vIdProducerNode	varchar(100) := '/posterminalmodel/posterminalproducer/@id';
		
		
	begin
		-- get data from xml
		vIdModel := cast(extract_value(vIdNode, posterminalModelData) as bigint);
		vNameModel := extract_value(vNameNode, posterminalModelData);
		vIdProducer := cast(extract_value(vIdProducerNode, posterminalModelData) as integer);
		
		-- insert data into table
		insert into PosterminalModel(
				idPosterminalProducer, namePosterminalModel)
			values(
				vIdProducer, vNameModel)
			returning idPosterminalModel into vIdModel;
			posterminalModelData := posterminalModel2Xml(vIdModel, null, null); 	-- return only id
			
		executeStatusData := statusCall(successcode(), insertText()); -- status data
		return;

	end;
$$ language plpgsql VOLATILE;